﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MvcShop.Models.Repositories
{
    public abstract class BaseCriteria : ICriteria
    {
        public const string FieldPrefix = "it.";
        public const string NamePrefix = "@";

        public BaseCriteria()
        {
            this.CriteriaType = CriteriaType.Expression;
        }

        #region ICriteria 成员

        public abstract string Expression { get; }


        public ICriteria And(ICriteria other)
        {
            return new AndCriteria(this, other);
        }

        public ICriteria Or(ICriteria other)
        {
            return new OrCriteria(this, other);
        }

        public ICriteria Not()
        {
            return new NotCriteria(this);
        }

        public ICriteria BracketsAnd(ICriteria other)
        {
            return new BracketsAndCriteria(this, other);
        }

        public ICriteria BracketsOr(ICriteria other)
        {
            return new BracketsOrCriteria(this, other);
        }

        protected List<CriteriaParameter> parameters = new List<CriteriaParameter>();
        public CriteriaParameter[] Parameters
        {
            get { return parameters.ToArray(); }
        }

        public CriteriaType CriteriaType
        {
            get;
            protected set;
        }

        #endregion

        static protected string ParameterNameFormat(string field)
        {
            return field.Replace('.', '_');
        }
    } 
}
